<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('设备列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>设备标识：</label>
                                <input type="text" name="deviceIdentify"/>
                            </li>
                            <li>
                                <label>用户标识：</label>
                                <input type="text" name="userIdentify"/>
                            </li>
                            <li>
                                <label>imei：</label>
                                <input type="text" name="imei"/>
                            </li>
                            <li>
                                <label>imsi：</label>
                                <input type="text" name="imsi"/>
                            </li>
                            <li>
                                <label>oaid：</label>
                                <input type="text" name="oaid"/>
                            </li>
                            <li>
                                <label>gaid：</label>
                                <input type="text" name="gaid"/>
                            </li>
                            <li>
                                <label>安卓ID：</label>
                                <input type="text" name="androidId"/>
                            </li>
                            <li>
                                <label>Mac地址：</label>
                                <input type="text" name="mac"/>
                            </li>
                            <li>
                                <label>应用：</label>
                                <select name="productId" id="productId" onchange="selectProduct()">
                                    <option value="">请选择应用</option>
                                    <option th:each="product:${productList}" th:text="${product.name}" th:value="${product.id}"></option>
                                </select>
                            </li>
                            <li>
                                <label>应用版本：</label>
                                <select name="version" id="version">
                                    <option value="">请选择应用版本</option>
                                </select>
                            </li>
                            <li>
                                <label>渠道：</label>
                                <select name="channelId">
                                    <option value="">请选择渠道</option>
                                    <option th:each="channel:${channelList}" th:text="${channel.name}" th:value="${channel.code}"></option>
                                </select>
                            </li>
                            <li>
                                <label>手机品牌：</label>
                                <select name="phoneBrand" id="phoneBrand" >
                                    <option value="">请选择手机品牌</option>
                                    <option th:each="phoneBrand:${phoneBrandList}" th:text="${phoneBrand}" th:value="${phoneBrand}" ></option>
                                </select>
                            </li>
                            <li>
                                <label>手机型号：</label>
                                <select name="phoneModel" id="phoneModel">
                                    <option value="">请选择手机型号</option>
                                    <option th:each="phoneModel:${phoneModelList}" th:text="${phoneModel}" th:value="${phoneModel}" ></option>
                                </select>
                            </li>
                            <li>
                                <label>是否黑名单：</label>
                                <select name="isBlacklist" th:with="type=${@dict.getType('sys_business_yes_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                开始时间：
                                <input type="text" class="time-input" placeholder="请选择开始时间" id="startCreateTime" name="startCreateTime" th:value="${#dates.format(startCreateTime, 'yyyy-MM-dd')}"/>
                            </li>
                            <li>
                                截止时间：
                                <input type="text" class="time-input" placeholder="请选择结束时间" id="endCreateTime" name="endCreateTime" th:value="${#dates.format(endCreateTime, 'yyyy-MM-dd')}"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;查询</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="privateReset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <!--<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="product:device:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="product:device:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="product:device:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="product:device:export">
                    <i class="fa fa-download"></i> 导出
                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" class="table table-bordered table-hover" style="table-layout:fixed;word-break:break-all;"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('product:device:edit')}]];
        var removeFlag = [[${@permission.hasPermi('product:device:remove')}]];
        var yes_no = [[${@dict.getType('sys_business_yes_no')}]];
        var prefix = ctx + "product/device";

        window.onload = function() {
            timeInit();
        }

        function timeInit() {
            var dateEnd = new Date();
            var dateStart = $.common.get7DaysBefore(dateEnd);
            var dateEndStr = $.common.dateFormat(new Date(), "yyyy-MM-dd");
            var dateStartStr = $.common.dateFormat("2022-03-01", "yyyy-MM-dd");
            $('#startCreateTime').val(dateStartStr);
            $('#endCreateTime').val(dateEndStr);
        }

        function privateReset() {
            $.form.reset();
            timeInit();
        }

        $(function() {
            timeInit();
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/form",
                updateUrl: prefix + "/form/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "用户设备",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '${comment}',
                    visible: false
                },
                {
                    field: 'deviceIdentify',
                    title: '设备标识',
                    width: 90
                },
                {
                    field: 'productName',
                    title: '首次使用的应用',
                    width: 110
                },
                {
                    field: 'version',
                    title: '首次应用的版本',
                    width: 110
                },
                {
                    field: 'channelId',
                    title: '渠道',
                    width: 80
                },
                {
                    field: 'userIdentify',
                    title: '用户标识',
                    formatter: function(value, row, index) {
                        if (value != null) {
                            return '<a href="javascript:void(0)" onclick="detail(\'' + row.userId + '\')">' + value + '</a>';
                        }
                    },
                    width: 90
                },
                {
                    field: 'productNum',
                    title: '应用数量',
                    formatter: function(value, row, index) {
                        if (value != null) {
                            return '<a href="javascript:void(0)" onclick="productList(\'' + row.id + '\')">' + value + '</a>';
                        }
                    },
                    width: 70
                },
                {
                    field: 'imei',
                    title: 'imei',
                    width: 100
                },
                {
                    field: 'imsi',
                    title: 'imsi',
                    width: 100
                },
                {
                    field: 'oaid',
                    title: 'oaid',
                    width: 100
                },
                {
                    field: 'gaid',
                    title: 'gaid',
                    width: 100
                },
                {
                    field: 'androidId',
                    title: '安卓id',
                    width: 100
                },
                {
                    field: 'phoneName',
                    title: '手机名称',
                    width: 100
                },
                {
                    field: 'phoneBrand',
                    title: '手机品牌',
                    width: 100
                },
                {
                    field: 'phoneModel',
                    title: '手机型号',
                    width: 100
                },
                {
                    field: 'baseOs',
                    title: '操作系统',
                    width: 100
                },
                {
                    field: 'branchOs',
                    title: '定制系统',
                    width: 100
                },
                {
                    field: 'mainBoardName',
                    title: '手机主板名称',
                    width: 100
                },
                {
                    field: 'hardwarePlatform',
                    title: '手机硬件平台',
                    width: 100
                },
                {
                    field: 'cpuFrame',
                    title: 'cpu框架',
                    width: 100
                },
                {
                    field: 'cpuCoreNum',
                    title: 'cpu核数',
                    width: 100
                },
                {
                    field: 'cpuMaxFreq',
                    title: 'cpu最大频率',
                    width: 100
                },
                {
                    field: 'cpuMinFreq',
                    title: 'cpu最小频率',
                    width: 100
                },
                {
                    field: 'androidVersion',
                    title: '安卓版本',
                    width: 100
                },
                {
                    field: 'sdkVersion',
                    title: 'sdk版本',
                    width: 100
                },
                {
                    field: 'resolvingPower',
                    title: '分辨率',
                    width: 100
                },
                {
                    field: 'memory',
                    title: '内存',
                    width: 100
                },
                {
                    field: 'insideStorage',
                    title: '内部存储',
                    width: 100
                },
                {
                    field: 'screenPixelDensity',
                    title: '屏幕像素密度',
                    width: 100
                },
                {
                    field: 'screenDensity',
                    title: '屏幕密度',
                    width: 100
                },
                {
                    field: 'frontCameraPixel',
                    title: '前置摄像头像素',
                    width: 110
                },
                {
                    field: 'postCameraPixel',
                    title: '后置摄像头像素',
                    width: 110
                },
                {
                    field: 'batteryCapacity',
                    title: '电池容量',
                    width: 100
                },
                {
                    field: 'batteryTech',
                    title: '电池技术',
                    width: 100
                },
                {
                    field: 'nfc',
                    title: 'nfc',
                    width: 100
                },
                {
                    field: 'mac',
                    title: 'mac地址',
                    width: 100
                },
                {
                    field: 'location',
                    title: '位置信息',
                    width: 100
                },
                {
                    field: 'lastApp',
                    title: '最后使用的应用',
                    width: 110
                },
                {
                    field: 'lastAppTime',
                    title: '最后应用的时间',
                    width: 110
                },
                {
                    field: 'isBlacklist',
                    title: '是否黑名单',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(yes_no, value);
                    },
                    width: 100
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    width: 90
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if (row.isBlacklist != 1){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="addBlackList(\'' + row.id + '\')"><i class="fa fa-edit"></i>添加黑名单</a> ');
                        }
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a class="btn btn-success btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a>');
                        return actions.join('');
                    },
                    width: 200
                }]
            };
            $.table.init(options);
        });


        function addBlackList(id) {
            $.modal.confirm("确认要添加到黑名单吗？", function() {
                $.get(prefix + '/addBlackList?id='+id, function(result) {
                    $.modal.msgSuccess("添加成功");
                    window.location.reload();
                });
            })
        }
        function detail(id) {
            $.modal.open("查看用户信息",prefix + "/getUserInfo/"+id);
        }
        function productList(id) {
            $.modal.open("已安装应用名称列表",prefix + "/productList/"+id);
        }

    function selectProduct() {
        var productId = $("#productId").val();
        $.ajax({
            type: "GET",
            url: prefix + "/addChangeProduct?productId="+productId,
            cache: false,
            dataType: 'json',
            success: function(result) {
                if (result) {
                    var html = "<option value=''>请选择应用版本</option>";
                    for (var i = 0; i < result.length; i++) {
                        html += "<option value='" + result[i] + "'>" + result[i] + "</option>"
                    }
                   $('#version').html(html);
                } else {
                    $.modal.alertError(result.msg);
                }
            },
            error: function(error) {
                $.modal.alertWarning("失败。");
            }
        });
    }
    </script>
</body>
</html>